package interfaces.clients.authorization;

import interfaces.clients.authorization.exceptions.*;

/**
 * The interface of authorization.
 *
 * @author Manujlov Maxim
 */
public interface Authorizer {
  /**
   * The function gets user data and returns user id.
   *
   * @param data user authorization data
   * @throws UserDoesNotExistException if the user does not exist
   * @throws WrongPasswordException if the password is wrong
   * @return user data
   */
  public UserData authorize(AuthorizationData data) throws UserDoesNotExistException, WrongPasswordException;

  /**
   * The function returns user data.
   *
   * @param uName user name
   * @throws UserDoesNotExistException if the user doesn't exist
   * @return user data
   */
  public UserData getUserData(String uName) throws UserDoesNotExistException;

  /**
   * The function adds user to database.
   *
   * @param data user authorization data
   * @throws MaximallyPossibleQuantityOfTheUsersException if the quantity of the users is maximally possible
   * @throws ImpossibleStringException if the name or the password is longer than 65535 symbols
   * @throws UserAlreadyExistsException if the user already exists
   * @return user data
   */
  public UserData addUser(AuthorizationData data) throws UserAlreadyExistsException, ImpossibleStringException,
                                                         MaximallyPossibleQuantityOfTheUsersException;

  /**
   * The function deletes user from database.
   *
   * @param data user authorization data
   * @throws UserDoesNotExistException if the user does not exist
   * @throws WrongPasswordException if the password is wrong
   * @return user data
   */
  public UserData deleteUser(AuthorizationData data) throws UserDoesNotExistException, WrongPasswordException;

  /**
   * The function changes user name.
   *
   * @param data user authorization data
   * @param newName new user name
   * @throws UserDoesNotExistException if the user does not exist
   * @throws WrongPasswordException if the password is wrong
   * @throws UserAlreadyExistsException if the user already exists
   * @return user data
   */
  public UserData changeUserName(AuthorizationData data, String newName) throws UserDoesNotExistException,
                                                                                WrongPasswordException,
                                                                                UserAlreadyExistsException;
  /**
   * The function changes user password.
   *
   * @param data user authorization data
   * @param newPwd new user password
   * @throws UserDoesNotExistException if the user does not exist
   * @throws WrongPasswordException if the password is wrong
   * @return user data
   */
  public UserData changeUserPassword(AuthorizationData data, String newPwd) throws UserDoesNotExistException,
                                                                                   WrongPasswordException;
  /**
   * The function checks if the user is in the database.
   *
   * @param uName user name
   * @return true, if the user exists, false, otherwise
   */
  public boolean userExists(String uName);

  /**
   * The function returns the quantity of the users.
   *
   * @return the quantity of the users
   */
  public int getUsersCount();
}
